<?php

class user_model extends CI_Model{
	
	protected static $table_name = 'userinfo';
	
    function __construct(){
        parent::__construct();
    }
    
    
    /**
     * 检查密码
     * @param unknown_type $phone
     * @param unknown_type $email
     * @param unknown_type $passwd
     * @return boolean
     */
    public function checkpass($phone = '', $email = '', $passwd = ''){
        $passwd = md5($passwd.$this->config->config['md5key']);
        if (empty($phone)){
            $data = array('phone'=>$phone);
        }else if (empty($email)){
            $data = array('email'=>$email);
        }else {
            return false;
        }
    	$data = $this->get($data);
    	if (empty($data))return false;
    	if ($data['passwd'] != $passwd) return false;
    	return true;
    }
    
    /**
     * 获取用户信息
     * @param unknown_type $uids
     */
    public function getuserbyuids($uids){
    	$query = $this->db->get_where_in(self::$table_name, 'uid', $uids);
    	$data = $query->result();
    	if (empty($data)){
    		return array();
    	}else{
    		return $data;
    	}
    }
    
    /**
     * 获取用户
     * @param unknown_type $uid
     */
    public function get($data){
    	$query = $this->db->get_where(self::$table_name, $data);
    	$data = $query->result();
    	if (empty($data)){
    		return array();
    	}else{
    		return $data[0];
    	}
    }
    
    /**
     * 
     * @param unknown_type $data
     */
    public function insert($data){
    	$rs = $this->db->insert(self::$table_name, $data);
    	if ($rs === false) return false;
    	return $this->db->insert_id();
    }
    
    /**
     * 批量增加
     * @param unknown_type $data
     * @return boolean
     */
    public function insert_batch($data){
    	return  $this->db->insert_batch(self::$table_name, $data);
    }
    
    /**
     * 
     * @param unknown_type $data
     */
    public function update($data){
    	if (empty($data['uid'])) return false;
    	$uid = $data['uid'];
    	unset($data['uid']);
    	return $this->db->update(self::$table_name,$data,array('uid'=>$uid));
    }
    
    
}

?>